# Maintainer: Václav Šmilauer <eu@doxos.eu>

_realname=highfive
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.7.1
pkgrel=1
pkgdesc='Modern header-only C++11 friendly interface for libhdf5 (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url='https://github.com/BlueBrain/HighFive'
license=('custom')
# besides cmake, build deps are for unit tests (at package build time)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-catch"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-boost"
  "${MINGW_PACKAGE_PREFIX}-opencv"
  "${MINGW_PACKAGE_PREFIX}-eigen3"
  "${MINGW_PACKAGE_PREFIX}-hdf5"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
depends=("${MINGW_PACKAGE_PREFIX}-hdf5")
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-boost"
  "${MINGW_PACKAGE_PREFIX}-opencv"
  "${MINGW_PACKAGE_PREFIX}-eigen3"
)
options=('staticlibs' '!strip' '!buildflags')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/BlueBrain/HighFive/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('25b4c51a94d1e670dc93b9b73f51e79b65d8ff49bcd6e5d5582d5ecd2789a249')

prepare(){
  mv "${srcdir}/HighFive-${pkgver}" "${_realname}-${pkgver}"
  cd "${_realname}-${pkgver}"
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  # HIGHFIVE_* options only affect tests (at package-build time),
  # not what is installed
  # (xtensor is not packaged, thus OFF)

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DHIGHFIVE_USE_BOOST=ON \
    -DHIGHFIVE_USE_EIGEN=ON \
    -DHIGHFIVE_USE_XTENSOR=OFF \
    -DHIGHFIVE_USE_OPENCV=ON \
    -DHIGHFIVE_UNIT_TESTS=OFF \
    -DHIGHFIVE_PARALLEL_HDF5=OFF \
    -DHIGHFIVE_BUILD_DOCS=OFF \
    -DCMAKE_RUNTIME_OUTPUT_DIRECTORY="${srcdir}/build-${MSYSTEM}" \
    -S ../${_realname}-${pkgver} -B .

  ${MINGW_PREFIX}/bin/cmake --build .
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  # run unit tests
  ${MINGW_PREFIX}/bin/ctest
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
